package Day10;

import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] prices = new int[n];
            for(int i = 0;i < n;i++){
                prices[i] = in.nextInt();
            }
            int max = 0;
            for(int i = 0,out = i + 1;out < n;out++){//i表示第i天买入的，out表示第out天卖出
                if(prices[i] < prices[out]){
                    max = Math.max(max,prices[out] - prices[i]);
                }
                if(out == n - 1){
                    i++;
                    out = i+ 1;
                }
            }
            System.out.println(max);
        }
    }
}
